<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Collision Test / UUID.js</title>
    <script type="text/javascript" src="../src/uuid.js"></script>
  </head>
  <body>
    <h1>Collision Test / UUID.js</h1>
    <script type="text/javascript">
      // <![CDATA[
      var n = 1 << 14;
      var count = 0;
      var table = {};

      var messages = [];
      var uuids = new Array(n * 3);

      messages.push("Begin collision test with " + (n * 2) + " version 4 UUIDs and " + n + " version 1 UUIDs.");
      var startOn = new Date().getTime();
      for (var i = 0; i < n; i++) {
        var xs = [UUID.generate(), String(UUID.genV4()), String(UUID.genV1())];
        for (var j = 0, len = xs.length; j < len; j++) {
          uuids[i + j * n] = xs[j];
          if (table[xs[j]]) {
            count++;
            messages.push("Collision\t" + xs[j]);
          } else {
            table[xs[j]] = true;
          }
        }
      }
      var endOn = new Date().getTime();
      messages.push("End collision test: " + count + " collision(s) detected and " + (endOn - startOn) + " milliseconds taken.");
      // ]]>
    </script>
    <h2>Test Messages</h2>
    <pre><script type="text/javascript">document.writeln(messages.join("\n"));</script></pre>
    <h2>Generated UUIDs</h2>
    <pre><script type="text/javascript">document.writeln(uuids.join("\n"));</script></pre>
  </body>
</html>
